package com.servlets;

import com.utils.VerifyCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;

@WebServlet("/VerifyCodeServlet")
public class VerifyCodeServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //创建对象
        VerifyCode verifyCode = new VerifyCode();
        //获取图片对象
        BufferedImage image = verifyCode.getImage();
        //获取图片文本内容
        String vc = verifyCode.getText();
        //将系统生成的图片保存在session中
        request.getSession().setAttribute("vc",vc);
        //向浏览器输送图片
        verifyCode.output(image, response.getOutputStream());
    }
}
